-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HOTFIX] fix fwd trans conv MakeFwdCtxAndProblem() intenal API #2476
Conversation
@carlushuang It's sad to say that, but this PR removes implementation of forward transposed convolution and replaces it by non-transposed one and therefore should not be merged ;) Please see e.g. PR 1804 in the private MIOpen repo for more info.
That's correct. When we use output tensor (NKHW) as input (NC'HW), and use input (NCHW) as output (NK'HW), the layout of weights KCYX automatically considered as C'K'YX so we do not need to do anything (except applying Bwd conv instead of Fwd etc). |
Our implementation in code like |
@atamazov I understand what you are saying, however, that does not align with the following change in
Since then the above transformation would happen inside MIOpen automatically as you mentioned. |
Looks like I should give a more detailed explanation. Generally, the implementation of something in the driver has nothing to do with the implementation in the library. The general requirement is that the driver must produce valid inputs, validate outputs correctly, and make valid API calls to the library, while the library must correctly interpret inputs and write valid outputs. The requirement may be interpreted as an "alignment" between the library and the driver but I do not think this is really so. How the driver produces valid layouts for transposed convolutionsThe driver does not swap input and output tensors, but swaps K and C in the layout of weights instead (as you are correctly mentioning). The result is that tensor layouts comply with PyTorch requirements for the transposed convolution: NCHW in, NKHW out, CKYX weights. This is good, but has no effect on what happens in the library. The library must handle tensor layouts correctly by itself. How the library handles the tensor layouts of transposed convolutionsAs we know, the library gets NCHW in, CKYX weights and NKHW out. The idea is to swap input and output and use Forward instead of Backward (and vice versa). So what happens:
As you can see, after swapping input and output tensors, we have normal NCHW layout internally and therefore we can leverage existing normal convolutions (but in opposite directions) to implement the transposed ones. |
x and y are swapped. Please compare normal Backward call: |
I am getting bogged down in discussions, but still keep the hope that is would help someone. |
The x/y swap I mean is between forward, and forward+trans(which calls into bwd code), these 2 parts are swapped or not. So actually it is not. The code change I did in this PR is also keep the same behavior, that not swap x/y in fwd and fwd+trans case. |
src/solver/gemm_bwd.cpp
Outdated
@@ -43,6 +43,7 @@ | |||
MIOPEN_DECLARE_ENV_VAR(MIOPEN_CONV_PRECISE_ROCBLAS_TIMING) | |||
|
|||
#define WORKAROUND_MIOPENGEMM_ISSUE_59 1 | |||
#define WORKAROUND_MIOPENGEMM_ISSUE_2474 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carlushuang It's likely unnecessary since in the release dockers we are not seeing these issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should not push that commit related to bwd-gemm on my local machine. Now that commit is reverted
This reverts commit 0816200.
@junliume thanks, I revert that commit related to bwd-gemm now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NO GO sorry.
auto problem = ProblemDescription{ | ||
miopen::deref(xDesc), miopen::deref(wDesc), miopen::deref(yDesc), conv, direction}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2476 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atamazov Is there any alternative we can compare as a quick patch fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@junliume Fix is done, in local testing. ETA for PR is tomorrow morning
@atamazov Sounds good, lets wait for your fix! |
replaced by #2487 and agreed by author. Keep this page for valuable information. |
This is to fix issue : #2459
The root cause is not
ValidateGroupCount
, but some discrepancy in different conv APIs. Here we modifyMakeFwdCtxAndProblem()
API to match the conv fwd transposed requirement.A quick review of transposed_conv :
in fwd we have
N*C*Hi*Wi @ K*C*Y*X -> N*K*Ho*Wo
. If this is a transposed conv, then it's actually is a backward conv, the layout of weight tensor need change toC*K*Y*X
(swap theC
andK
).According to pytorch standard https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose2d.html
the layout for weight for tansposed_conv is
input_ch * output_ch * Y * X
, this indicates that for transposed fwd conv, the only requirement is to swap weightC
andK
.This is luckily done by the MIOpenDriver
conv_driver.hpp
Line : 1001~1011The only requirement is when detecting transposed conv in conv-fwd, we need to set the proper argument to direct it to conv-bwd ( assuming the
C
/K
swap is done by user or byMIOpenDriver
)This PR fix the bug for
MakeFwdCtxAndProblem()
, we do not need to swap thexDesc
/yDesc
if detecting this is a transposed, because if this is actually transposed-conv, we only need to set the direction to backward, then it's OK. This is also aligned with src/convolution_api.cpp miopenConvolutionForward(), thexDesc
/yDesc
do not need to swap